{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "578acb38",
   "metadata": {},
   "source": [
    "# 多次对话\n",
    "要想用for循环实现多次对话\n",
    "就不能只识别循环识别一段语音。\\\\\n",
    "一段语音一次识别\n",
    "多段语音多次识别."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e1c0a287",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "********** Start recording for 5 seconds! **********\n",
      "..........1s\n",
      "\n",
      "..........2s\n",
      "\n",
      "..........3s\n",
      "\n",
      "..........4s\n",
      "\n",
      "..........5s\n",
      "\n",
      "********** Stop recording! **********\n",
      "{\"refresh_token\":\"25.665180adf5e4bcc02043b6d013e3e95d.315360000.2060930883.282335-118650883\",\"expires_in\":2592000,\"session_key\":\"9mzdDFP\\/VelsfVE2bZMlosb8CaYjvAhXtigTGJkEI70qREWZ+QTTG3E5p\\/zxIocvI5v2mExu\\/BNwJE0Sse0YigQ48HV5ti4=\",\"access_token\":\"24.7fcc3d66e29e4a343d2b708d017da8c2.2592000.1748162883.282335-118650883\",\"scope\":\"public audio_voice_assistant_get audio_tts_post brain_all_scope brain_enhanced_asr brain_speech_realtime brain_asr_async wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test\\u6743\\u9650 vis-classify_flower lpq_\\u5f00\\u653e cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_\\u5f00\\u653eScope vis-ocr_\\u865a\\u62df\\u4eba\\u7269\\u52a9\\u7406 idl-video_\\u865a\\u62df\\u4eba\\u7269\\u52a9\\u7406 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online smartapp_gov_aladin_to_xcx\",\"session_secret\":\"3b7e930efbce61d3d3ae677148321072\"}\n",
      "\n",
      "{'refresh_token': '25.665180adf5e4bcc02043b6d013e3e95d.315360000.2060930883.282335-118650883', 'expires_in': 2592000, 'session_key': '9mzdDFP/VelsfVE2bZMlosb8CaYjvAhXtigTGJkEI70qREWZ+QTTG3E5p/zxIocvI5v2mExu/BNwJE0Sse0YigQ48HV5ti4=', 'access_token': '24.7fcc3d66e29e4a343d2b708d017da8c2.2592000.1748162883.282335-118650883', 'scope': 'public audio_voice_assistant_get audio_tts_post brain_all_scope brain_enhanced_asr brain_speech_realtime brain_asr_async wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online smartapp_gov_aladin_to_xcx', 'session_secret': '3b7e930efbce61d3d3ae677148321072'}\n",
      "SUCCESS WITH TOKEN: 24.7fcc3d66e29e4a343d2b708d017da8c2.2592000.1748162883.282335-118650883 ; EXPIRES IN SECONDS: 2592000\n",
      "url is http://vop.baidu.com/server_api?cuid=123456PYTHON&token=24.7fcc3d66e29e4a343d2b708d017da8c2.2592000.1748162883.282335-118650883&dev_pid=1537\n",
      "header is {'Content-Type': 'audio/wav; rate=16000', 'Content-Length': 200044}\n",
      "Request time cost 0.700116\n",
      "\n",
      "{\"corpus_no\":\"7497169856638309364\",\"err_msg\":\"success.\",\"err_no\":0,\"result\":[\"\"],\"sn\":\"787767609981745570883\"}\n",
      "\n",
      "我听到你说 : \n",
      "第0次识别\n",
      "********** Start recording for 5 seconds! **********\n",
      "..........1s\n",
      "\n",
      "..........2s\n",
      "\n",
      "..........3s\n",
      "\n",
      "..........4s\n",
      "\n",
      "..........5s\n",
      "\n",
      "********** Stop recording! **********\n",
      "{\"refresh_token\":\"25.3f296107aaa3a10999000e8321f4592c.315360000.2060930890.282335-118650883\",\"expires_in\":2592000,\"session_key\":\"9mzdX7ya0cWJxC\\/TRy5TlRWsOQhUdI0dyVcJPC8QacU81\\/tbio5unDzL9MvmdNJcSdtY0zJdB3c1TJCjsT2clM\\/dJ+5yGnI=\",\"access_token\":\"24.df466cc5809e697f949f2e403980a7c4.2592000.1748162890.282335-118650883\",\"scope\":\"public audio_voice_assistant_get audio_tts_post brain_all_scope brain_enhanced_asr brain_speech_realtime brain_asr_async wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test\\u6743\\u9650 vis-classify_flower lpq_\\u5f00\\u653e cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_\\u5f00\\u653eScope vis-ocr_\\u865a\\u62df\\u4eba\\u7269\\u52a9\\u7406 idl-video_\\u865a\\u62df\\u4eba\\u7269\\u52a9\\u7406 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online smartapp_gov_aladin_to_xcx\",\"session_secret\":\"2306f5dd997530f8a7668eb3f4409968\"}\n",
      "\n",
      "{'refresh_token': '25.3f296107aaa3a10999000e8321f4592c.315360000.2060930890.282335-118650883', 'expires_in': 2592000, 'session_key': '9mzdX7ya0cWJxC/TRy5TlRWsOQhUdI0dyVcJPC8QacU81/tbio5unDzL9MvmdNJcSdtY0zJdB3c1TJCjsT2clM/dJ+5yGnI=', 'access_token': '24.df466cc5809e697f949f2e403980a7c4.2592000.1748162890.282335-118650883', 'scope': 'public audio_voice_assistant_get audio_tts_post brain_all_scope brain_enhanced_asr brain_speech_realtime brain_asr_async wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online smartapp_gov_aladin_to_xcx', 'session_secret': '2306f5dd997530f8a7668eb3f4409968'}\n",
      "SUCCESS WITH TOKEN: 24.df466cc5809e697f949f2e403980a7c4.2592000.1748162890.282335-118650883 ; EXPIRES IN SECONDS: 2592000\n",
      "url is http://vop.baidu.com/server_api?cuid=123456PYTHON&token=24.df466cc5809e697f949f2e403980a7c4.2592000.1748162890.282335-118650883&dev_pid=1537\n",
      "header is {'Content-Type': 'audio/wav; rate=16000', 'Content-Length': 400044}\n",
      "Request time cost 0.679942\n",
      "\n",
      "{\"corpus_no\":\"7497169891119006022\",\"err_msg\":\"success.\",\"err_no\":0,\"result\":[\"\"],\"sn\":\"257681914061745570891\"}\n",
      "\n",
      "我听到你说 : \n",
      "第1次识别\n",
      "********** Start recording for 5 seconds! **********\n",
      "..........1s\n",
      "\n",
      "..........2s\n",
      "\n",
      "..........3s\n",
      "\n",
      "..........4s\n",
      "\n",
      "..........5s\n",
      "\n",
      "********** Stop recording! **********\n",
      "{\"refresh_token\":\"25.dfb714037b4e090ced4d6e1098154f55.315360000.2060930898.282335-118650883\",\"expires_in\":2592000,\"session_key\":\"9mzdWBIjP8EzB9Qng7GXTvBNuQPO9aDoo4A2VI7CxHgiVXF5L\\/aBED3ibnj02Y\\/JoDU+CADGxro5fn3mLjPpfFnYVQYfv4o=\",\"access_token\":\"24.cb59484ef488177908f22fb000007c7e.2592000.1748162898.282335-118650883\",\"scope\":\"public audio_voice_assistant_get audio_tts_post brain_all_scope brain_enhanced_asr brain_speech_realtime brain_asr_async wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test\\u6743\\u9650 vis-classify_flower lpq_\\u5f00\\u653e cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_\\u5f00\\u653eScope vis-ocr_\\u865a\\u62df\\u4eba\\u7269\\u52a9\\u7406 idl-video_\\u865a\\u62df\\u4eba\\u7269\\u52a9\\u7406 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online smartapp_gov_aladin_to_xcx\",\"session_secret\":\"49e222ee1076b09940751f8bcc93f734\"}\n",
      "\n",
      "{'refresh_token': '25.dfb714037b4e090ced4d6e1098154f55.315360000.2060930898.282335-118650883', 'expires_in': 2592000, 'session_key': '9mzdWBIjP8EzB9Qng7GXTvBNuQPO9aDoo4A2VI7CxHgiVXF5L/aBED3ibnj02Y/JoDU+CADGxro5fn3mLjPpfFnYVQYfv4o=', 'access_token': '24.cb59484ef488177908f22fb000007c7e.2592000.1748162898.282335-118650883', 'scope': 'public audio_voice_assistant_get audio_tts_post brain_all_scope brain_enhanced_asr brain_speech_realtime brain_asr_async wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online smartapp_gov_aladin_to_xcx', 'session_secret': '49e222ee1076b09940751f8bcc93f734'}\n",
      "SUCCESS WITH TOKEN: 24.cb59484ef488177908f22fb000007c7e.2592000.1748162898.282335-118650883 ; EXPIRES IN SECONDS: 2592000\n",
      "url is http://vop.baidu.com/server_api?cuid=123456PYTHON&token=24.cb59484ef488177908f22fb000007c7e.2592000.1748162898.282335-118650883&dev_pid=1537\n",
      "header is {'Content-Type': 'audio/wav; rate=16000', 'Content-Length': 600044}\n",
      "Request time cost 0.793152\n",
      "通信框架嗯。\n",
      "{\"corpus_no\":\"7497169921087899313\",\"err_msg\":\"success.\",\"err_no\":0,\"result\":[\"通信框架嗯。\"],\"sn\":\"978065207491745570898\"}\n",
      "\n",
      "我听到你说 : 通信框架嗯。\n",
      "第2次识别\n",
      "********** Start recording for 5 seconds! **********\n",
      "..........1s\n",
      "\n",
      "..........2s\n",
      "\n",
      "..........3s\n",
      "\n",
      "..........4s\n",
      "\n",
      "..........5s\n",
      "\n",
      "********** Stop recording! **********\n",
      "{\"refresh_token\":\"25.0e502f5cd072dd6d9529a7131aac7c30.315360000.2060930905.282335-118650883\",\"expires_in\":2592000,\"session_key\":\"9mzdA86ZeSiZFz87JqPk7TvVLQZqwEgxhBrWsv\\/wB2s9uCfIIgOozajdZ6mD3pbOrwxL7NNfS2Lg3kSiHP\\/1hcxbs4VZJiM=\",\"access_token\":\"24.8d66c5eda5041d5040be1d673d1b47ef.2592000.1748162905.282335-118650883\",\"scope\":\"public audio_voice_assistant_get audio_tts_post brain_all_scope brain_enhanced_asr brain_speech_realtime brain_asr_async wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test\\u6743\\u9650 vis-classify_flower lpq_\\u5f00\\u653e cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_\\u5f00\\u653eScope vis-ocr_\\u865a\\u62df\\u4eba\\u7269\\u52a9\\u7406 idl-video_\\u865a\\u62df\\u4eba\\u7269\\u52a9\\u7406 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online smartapp_gov_aladin_to_xcx\",\"session_secret\":\"6289fc33067b63db8527a9b033968f5d\"}\n",
      "\n",
      "{'refresh_token': '25.0e502f5cd072dd6d9529a7131aac7c30.315360000.2060930905.282335-118650883', 'expires_in': 2592000, 'session_key': '9mzdA86ZeSiZFz87JqPk7TvVLQZqwEgxhBrWsv/wB2s9uCfIIgOozajdZ6mD3pbOrwxL7NNfS2Lg3kSiHP/1hcxbs4VZJiM=', 'access_token': '24.8d66c5eda5041d5040be1d673d1b47ef.2592000.1748162905.282335-118650883', 'scope': 'public audio_voice_assistant_get audio_tts_post brain_all_scope brain_enhanced_asr brain_speech_realtime brain_asr_async wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online smartapp_gov_aladin_to_xcx', 'session_secret': '6289fc33067b63db8527a9b033968f5d'}\n",
      "SUCCESS WITH TOKEN: 24.8d66c5eda5041d5040be1d673d1b47ef.2592000.1748162905.282335-118650883 ; EXPIRES IN SECONDS: 2592000\n",
      "url is http://vop.baidu.com/server_api?cuid=123456PYTHON&token=24.8d66c5eda5041d5040be1d673d1b47ef.2592000.1748162905.282335-118650883&dev_pid=1537\n",
      "header is {'Content-Type': 'audio/wav; rate=16000', 'Content-Length': 800044}\n",
      "Request time cost 0.889628\n",
      "通信框架嗯。\n",
      "{\"corpus_no\":\"7497169954656091491\",\"err_msg\":\"success.\",\"err_no\":0,\"result\":[\"通信框架嗯。\"],\"sn\":\"5946960151745570906\"}\n",
      "\n",
      "我听到你说 : 通信框架嗯。\n",
      "第3次识别\n",
      "********** Start recording for 5 seconds! **********\n",
      "..........1s\n",
      "\n",
      "..........2s\n",
      "\n",
      "..........3s\n",
      "\n",
      "..........4s\n",
      "\n",
      "..........5s\n",
      "\n",
      "********** Stop recording! **********\n",
      "{\"refresh_token\":\"25.078b937a7e5b5299d822dc816b3e8cae.315360000.2060930913.282335-118650883\",\"expires_in\":2592000,\"session_key\":\"9mzdDA1xB4IQTMXZlAa4q4I2muxRs3jnbT0njZZZBwHLastsVxJFhdwiDI8l1IjNzKR0QmOtkQereLUqEMYUT4eDoraYJaM=\",\"access_token\":\"24.78bae05f63e7f68ba226e80c2aea55fe.2592000.1748162913.282335-118650883\",\"scope\":\"public audio_voice_assistant_get audio_tts_post brain_all_scope brain_enhanced_asr brain_speech_realtime brain_asr_async wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test\\u6743\\u9650 vis-classify_flower lpq_\\u5f00\\u653e cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_\\u5f00\\u653eScope vis-ocr_\\u865a\\u62df\\u4eba\\u7269\\u52a9\\u7406 idl-video_\\u865a\\u62df\\u4eba\\u7269\\u52a9\\u7406 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online smartapp_gov_aladin_to_xcx\",\"session_secret\":\"85531088600688e426df0238c9f8d7b8\"}\n",
      "\n",
      "{'refresh_token': '25.078b937a7e5b5299d822dc816b3e8cae.315360000.2060930913.282335-118650883', 'expires_in': 2592000, 'session_key': '9mzdDA1xB4IQTMXZlAa4q4I2muxRs3jnbT0njZZZBwHLastsVxJFhdwiDI8l1IjNzKR0QmOtkQereLUqEMYUT4eDoraYJaM=', 'access_token': '24.78bae05f63e7f68ba226e80c2aea55fe.2592000.1748162913.282335-118650883', 'scope': 'public audio_voice_assistant_get audio_tts_post brain_all_scope brain_enhanced_asr brain_speech_realtime brain_asr_async wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online smartapp_gov_aladin_to_xcx', 'session_secret': '85531088600688e426df0238c9f8d7b8'}\n",
      "SUCCESS WITH TOKEN: 24.78bae05f63e7f68ba226e80c2aea55fe.2592000.1748162913.282335-118650883 ; EXPIRES IN SECONDS: 2592000\n",
      "url is http://vop.baidu.com/server_api?cuid=123456PYTHON&token=24.78bae05f63e7f68ba226e80c2aea55fe.2592000.1748162913.282335-118650883&dev_pid=1537\n",
      "header is {'Content-Type': 'audio/wav; rate=16000', 'Content-Length': 1000044}\n",
      "Request time cost 1.135138\n",
      "通信框架嗯。\n",
      "{\"corpus_no\":\"7497169985527782015\",\"err_msg\":\"success.\",\"err_no\":0,\"result\":[\"通信框架嗯。\"],\"sn\":\"412408064291745570913\"}\n",
      "\n",
      "我听到你说 : 通信框架嗯。\n",
      "第4次识别\n",
      "********** Start recording for 5 seconds! **********\n",
      "..........1s\n",
      "\n",
      "..........2s\n",
      "\n",
      "..........3s\n",
      "\n",
      "..........4s\n",
      "\n",
      "..........5s\n",
      "\n",
      "********** Stop recording! **********\n",
      "{\"refresh_token\":\"25.5dea781e3fa0ebabf382fa20522a420c.315360000.2060930920.282335-118650883\",\"expires_in\":2592000,\"session_key\":\"9mzdWEYLlEUz5GulexxRixTHUqB++a0TEKL0\\/tdQ22Og3sCCfVIphL94GriqTIckLmE5p4NXsZFLbceFEJp2\\/NW8ki836H0=\",\"access_token\":\"24.c63d1072c3cfd13d8c88b9200e52fe00.2592000.1748162920.282335-118650883\",\"scope\":\"public audio_voice_assistant_get audio_tts_post brain_all_scope brain_enhanced_asr brain_speech_realtime brain_asr_async wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test\\u6743\\u9650 vis-classify_flower lpq_\\u5f00\\u653e cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_\\u5f00\\u653eScope vis-ocr_\\u865a\\u62df\\u4eba\\u7269\\u52a9\\u7406 idl-video_\\u865a\\u62df\\u4eba\\u7269\\u52a9\\u7406 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online smartapp_gov_aladin_to_xcx\",\"session_secret\":\"b1577b7f2327d4bdbfd7c15d5800ee7b\"}\n",
      "\n",
      "{'refresh_token': '25.5dea781e3fa0ebabf382fa20522a420c.315360000.2060930920.282335-118650883', 'expires_in': 2592000, 'session_key': '9mzdWEYLlEUz5GulexxRixTHUqB++a0TEKL0/tdQ22Og3sCCfVIphL94GriqTIckLmE5p4NXsZFLbceFEJp2/NW8ki836H0=', 'access_token': '24.c63d1072c3cfd13d8c88b9200e52fe00.2592000.1748162920.282335-118650883', 'scope': 'public audio_voice_assistant_get audio_tts_post brain_all_scope brain_enhanced_asr brain_speech_realtime brain_asr_async wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online smartapp_gov_aladin_to_xcx', 'session_secret': 'b1577b7f2327d4bdbfd7c15d5800ee7b'}\n",
      "SUCCESS WITH TOKEN: 24.c63d1072c3cfd13d8c88b9200e52fe00.2592000.1748162920.282335-118650883 ; EXPIRES IN SECONDS: 2592000\n",
      "url is http://vop.baidu.com/server_api?cuid=123456PYTHON&token=24.c63d1072c3cfd13d8c88b9200e52fe00.2592000.1748162920.282335-118650883&dev_pid=1537\n",
      "header is {'Content-Type': 'audio/wav; rate=16000', 'Content-Length': 1200044}\n",
      "Request time cost 1.475381\n",
      "通信框架嗯。\n",
      "{\"corpus_no\":\"7497170019789353524\",\"err_msg\":\"success.\",\"err_no\":0,\"result\":[\"通信框架嗯。\"],\"sn\":\"911698999611745570921\"}\n",
      "\n",
      "我听到你说 : 通信框架嗯。\n",
      "第5次识别\n",
      "********** Start recording for 5 seconds! **********\n",
      "..........1s\n",
      "\n",
      "..........2s\n",
      "\n",
      "..........3s\n",
      "\n",
      "..........4s\n",
      "\n",
      "..........5s\n",
      "\n",
      "********** Stop recording! **********\n",
      "{\"refresh_token\":\"25.d7ab77c85f8b3af9be77ba798f146313.315360000.2060930929.282335-118650883\",\"expires_in\":2592000,\"session_key\":\"9mzdDcP9ZOMlWkFpR2enShKB0CZoQLks+oF7X6g3l7wAiUihFf7lXLxAtVVA9fHHK8\\/6MTO8sOXvPvGnE3cXZx8NWxirzoE=\",\"access_token\":\"24.652be364a4812ba6726c80744b4876c2.2592000.1748162929.282335-118650883\",\"scope\":\"public audio_voice_assistant_get audio_tts_post brain_all_scope brain_enhanced_asr brain_speech_realtime brain_asr_async wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test\\u6743\\u9650 vis-classify_flower lpq_\\u5f00\\u653e cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_\\u5f00\\u653eScope vis-ocr_\\u865a\\u62df\\u4eba\\u7269\\u52a9\\u7406 idl-video_\\u865a\\u62df\\u4eba\\u7269\\u52a9\\u7406 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online smartapp_gov_aladin_to_xcx\",\"session_secret\":\"eac15f151f28705508a42bf9628f79cf\"}\n",
      "\n",
      "{'refresh_token': '25.d7ab77c85f8b3af9be77ba798f146313.315360000.2060930929.282335-118650883', 'expires_in': 2592000, 'session_key': '9mzdDcP9ZOMlWkFpR2enShKB0CZoQLks+oF7X6g3l7wAiUihFf7lXLxAtVVA9fHHK8/6MTO8sOXvPvGnE3cXZx8NWxirzoE=', 'access_token': '24.652be364a4812ba6726c80744b4876c2.2592000.1748162929.282335-118650883', 'scope': 'public audio_voice_assistant_get audio_tts_post brain_all_scope brain_enhanced_asr brain_speech_realtime brain_asr_async wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online smartapp_gov_aladin_to_xcx', 'session_secret': 'eac15f151f28705508a42bf9628f79cf'}\n",
      "SUCCESS WITH TOKEN: 24.652be364a4812ba6726c80744b4876c2.2592000.1748162929.282335-118650883 ; EXPIRES IN SECONDS: 2592000\n",
      "url is http://vop.baidu.com/server_api?cuid=123456PYTHON&token=24.652be364a4812ba6726c80744b4876c2.2592000.1748162929.282335-118650883&dev_pid=1537\n",
      "header is {'Content-Type': 'audio/wav; rate=16000', 'Content-Length': 1400044}\n",
      "Request time cost 1.270101\n",
      "通信框架嗯。\n",
      "{\"corpus_no\":\"7497170054246142011\",\"err_msg\":\"success.\",\"err_no\":0,\"result\":[\"通信框架嗯。\"],\"sn\":\"467838800611745570929\"}\n",
      "\n",
      "我听到你说 : 通信框架嗯。\n",
      "第6次识别\n",
      "********** Start recording for 5 seconds! **********\n",
      "..........1s\n",
      "\n",
      "..........2s\n",
      "\n",
      "..........3s\n",
      "\n",
      "..........4s\n",
      "\n",
      "..........5s\n",
      "\n",
      "********** Stop recording! **********\n",
      "{\"refresh_token\":\"25.67ab4293f67575c52a66524fd6241014.315360000.2060930936.282335-118650883\",\"expires_in\":2592000,\"session_key\":\"9mzdDATKcHBqtbrnJMLKym8ioKv30XwW\\/ePgmrIGI2fBaiVIAsvxB65sZsXEJ9kM5WII32aNxSDhpheOrUsrieyAT26vyHs=\",\"access_token\":\"24.71ac0397315ab86c705bd3204d01451a.2592000.1748162936.282335-118650883\",\"scope\":\"public audio_voice_assistant_get audio_tts_post brain_all_scope brain_enhanced_asr brain_speech_realtime brain_asr_async wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test\\u6743\\u9650 vis-classify_flower lpq_\\u5f00\\u653e cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_\\u5f00\\u653eScope vis-ocr_\\u865a\\u62df\\u4eba\\u7269\\u52a9\\u7406 idl-video_\\u865a\\u62df\\u4eba\\u7269\\u52a9\\u7406 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online smartapp_gov_aladin_to_xcx\",\"session_secret\":\"b88b16c921bcc67361b375038c489939\"}\n",
      "\n",
      "{'refresh_token': '25.67ab4293f67575c52a66524fd6241014.315360000.2060930936.282335-118650883', 'expires_in': 2592000, 'session_key': '9mzdDATKcHBqtbrnJMLKym8ioKv30XwW/ePgmrIGI2fBaiVIAsvxB65sZsXEJ9kM5WII32aNxSDhpheOrUsrieyAT26vyHs=', 'access_token': '24.71ac0397315ab86c705bd3204d01451a.2592000.1748162936.282335-118650883', 'scope': 'public audio_voice_assistant_get audio_tts_post brain_all_scope brain_enhanced_asr brain_speech_realtime brain_asr_async wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online smartapp_gov_aladin_to_xcx', 'session_secret': 'b88b16c921bcc67361b375038c489939'}\n",
      "SUCCESS WITH TOKEN: 24.71ac0397315ab86c705bd3204d01451a.2592000.1748162936.282335-118650883 ; EXPIRES IN SECONDS: 2592000\n",
      "url is http://vop.baidu.com/server_api?cuid=123456PYTHON&token=24.71ac0397315ab86c705bd3204d01451a.2592000.1748162936.282335-118650883&dev_pid=1537\n",
      "header is {'Content-Type': 'audio/wav; rate=16000', 'Content-Length': 1600044}\n",
      "Request time cost 1.302488\n",
      "通信框架嗯，结束录音。\n",
      "{\"corpus_no\":\"7497170088638080895\",\"err_msg\":\"success.\",\"err_no\":0,\"result\":[\"通信框架嗯，结束录音。\"],\"sn\":\"508476994181745570937\"}\n",
      "\n",
      "我听到你说 : 通信框架嗯，结束录音。\n",
      "第7次识别\n",
      "********** Start recording for 5 seconds! **********\n",
      "..........1s\n",
      "\n",
      "..........2s\n",
      "\n",
      "..........3s\n",
      "\n",
      "..........4s\n",
      "\n",
      "..........5s\n",
      "\n",
      "********** Stop recording! **********\n",
      "{\"refresh_token\":\"25.4273449a23613c29175bf24415a067a5.315360000.2060930944.282335-118650883\",\"expires_in\":2592000,\"session_key\":\"9mzdWWkNoooBjN6uVv2w9CDq8zccRib4BvdS1k14u\\/svSpN0niiqc0LOBcrJLc6Z\\/\\/RZ4i0L4K+aH7wK2njWEaq6+oFBEXY=\",\"access_token\":\"24.b3f3a010adb61acb17b8545a49cff03d.2592000.1748162944.282335-118650883\",\"scope\":\"public audio_voice_assistant_get audio_tts_post brain_all_scope brain_enhanced_asr brain_speech_realtime brain_asr_async wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test\\u6743\\u9650 vis-classify_flower lpq_\\u5f00\\u653e cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_\\u5f00\\u653eScope vis-ocr_\\u865a\\u62df\\u4eba\\u7269\\u52a9\\u7406 idl-video_\\u865a\\u62df\\u4eba\\u7269\\u52a9\\u7406 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online smartapp_gov_aladin_to_xcx\",\"session_secret\":\"2763548a61688700399a389d30fabbe5\"}\n",
      "\n",
      "{'refresh_token': '25.4273449a23613c29175bf24415a067a5.315360000.2060930944.282335-118650883', 'expires_in': 2592000, 'session_key': '9mzdWWkNoooBjN6uVv2w9CDq8zccRib4BvdS1k14u/svSpN0niiqc0LOBcrJLc6Z//RZ4i0L4K+aH7wK2njWEaq6+oFBEXY=', 'access_token': '24.b3f3a010adb61acb17b8545a49cff03d.2592000.1748162944.282335-118650883', 'scope': 'public audio_voice_assistant_get audio_tts_post brain_all_scope brain_enhanced_asr brain_speech_realtime brain_asr_async wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online smartapp_gov_aladin_to_xcx', 'session_secret': '2763548a61688700399a389d30fabbe5'}\n",
      "SUCCESS WITH TOKEN: 24.b3f3a010adb61acb17b8545a49cff03d.2592000.1748162944.282335-118650883 ; EXPIRES IN SECONDS: 2592000\n",
      "url is http://vop.baidu.com/server_api?cuid=123456PYTHON&token=24.b3f3a010adb61acb17b8545a49cff03d.2592000.1748162944.282335-118650883&dev_pid=1537\n",
      "header is {'Content-Type': 'audio/wav; rate=16000', 'Content-Length': 1800044}\n",
      "Request time cost 1.380817\n",
      "通信框架嗯，结束录音嗯。\n",
      "{\"corpus_no\":\"7497170122970229640\",\"err_msg\":\"success.\",\"err_no\":0,\"result\":[\"通信框架嗯，结束录音嗯。\"],\"sn\":\"482667267841745570945\"}\n",
      "\n",
      "我听到你说 : 通信框架嗯，结束录音嗯。\n",
      "第8次识别\n",
      "********** Start recording for 5 seconds! **********\n",
      "..........1s\n",
      "\n",
      "..........2s\n",
      "\n",
      "..........3s\n",
      "\n",
      "..........4s\n",
      "\n",
      "..........5s\n",
      "\n",
      "********** Stop recording! **********\n",
      "{\"refresh_token\":\"25.02c3b7ca6c95e121a19de2b5da78ed8c.315360000.2060930952.282335-118650883\",\"expires_in\":2592000,\"session_key\":\"9mzdCy4pFiyPLNMZh7oIbUbOK5XaTXzvDWMHem0d3YVERpOfmnU+qd0HH82qKERu5zvMUcM0Rc\\/Uv3K+JtIUy78DQ8+IOOI=\",\"access_token\":\"24.067ec5f052af0f50ecce0babb66b6885.2592000.1748162952.282335-118650883\",\"scope\":\"public audio_voice_assistant_get audio_tts_post brain_all_scope brain_enhanced_asr brain_speech_realtime brain_asr_async wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test\\u6743\\u9650 vis-classify_flower lpq_\\u5f00\\u653e cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_\\u5f00\\u653eScope vis-ocr_\\u865a\\u62df\\u4eba\\u7269\\u52a9\\u7406 idl-video_\\u865a\\u62df\\u4eba\\u7269\\u52a9\\u7406 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online smartapp_gov_aladin_to_xcx\",\"session_secret\":\"c35bd80b8f3e1e80ffc69c3b85ca2e37\"}\n",
      "\n",
      "{'refresh_token': '25.02c3b7ca6c95e121a19de2b5da78ed8c.315360000.2060930952.282335-118650883', 'expires_in': 2592000, 'session_key': '9mzdCy4pFiyPLNMZh7oIbUbOK5XaTXzvDWMHem0d3YVERpOfmnU+qd0HH82qKERu5zvMUcM0Rc/Uv3K+JtIUy78DQ8+IOOI=', 'access_token': '24.067ec5f052af0f50ecce0babb66b6885.2592000.1748162952.282335-118650883', 'scope': 'public audio_voice_assistant_get audio_tts_post brain_all_scope brain_enhanced_asr brain_speech_realtime brain_asr_async wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online smartapp_gov_aladin_to_xcx', 'session_secret': 'c35bd80b8f3e1e80ffc69c3b85ca2e37'}\n",
      "SUCCESS WITH TOKEN: 24.067ec5f052af0f50ecce0babb66b6885.2592000.1748162952.282335-118650883 ; EXPIRES IN SECONDS: 2592000\n",
      "url is http://vop.baidu.com/server_api?cuid=123456PYTHON&token=24.067ec5f052af0f50ecce0babb66b6885.2592000.1748162952.282335-118650883&dev_pid=1537\n",
      "header is {'Content-Type': 'audio/wav; rate=16000', 'Content-Length': 2000044}\n",
      "Request time cost 1.000067\n",
      "识别失败,可能没生成result键\n",
      "识别失败,可能没有语音\n",
      "{\"err_msg\":\"speech too long.\",\"err_no\":3308,\"sn\":\"479347904011745570953\"}\n",
      "\n",
      "没有语音,返回不了东西给你\n"
     ]
    },
    {
     "ename": "TypeError",
     "evalue": "can only concatenate str (not \"NoneType\") to str",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[1], line 16\u001b[0m\n\u001b[0;32m     14\u001b[0m \u001b[38;5;66;03m# 识别这段语音，转换成文本\u001b[39;00m\n\u001b[0;32m     15\u001b[0m result_str \u001b[38;5;241m=\u001b[39m ar\u001b[38;5;241m.\u001b[39mVoice2Text(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtest\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mi\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m.wav\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m---> 16\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m我听到你说 : \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mresult_str\u001b[49m)\u001b[38;5;66;03m#打印识别结果\u001b[39;00m\n\u001b[0;32m     17\u001b[0m \u001b[38;5;66;03m#判断识别文本内容，并执行相应的操作\u001b[39;00m\n\u001b[0;32m     18\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m第\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mi\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m次识别\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
      "\u001b[1;31mTypeError\u001b[0m: can only concatenate str (not \"NoneType\") to str"
     ]
    }
   ],
   "source": [
    "#导入依赖包\n",
    "import time\n",
    "import asr_raw as ar  #百度语音识别包\n",
    "import webbrowser\n",
    "import tts as tts     #百度语音合成包\n",
    "from RecordPlay import recorder#录音和播放函数\n",
    "import os             #标准os库\n",
    "\n",
    "#录音5s,保存音频到test.wav文件\n",
    "r = recorder()\n",
    "i = 0\n",
    "while True:\n",
    "    r.recorder(f\"test{i}.wav\")\n",
    "    # 识别这段语音，转换成文本\n",
    "    result_str = ar.Voice2Text(f\"test{i}.wav\")\n",
    "    try :\n",
    "        print(\"我听到你说 : \" + result_str)#打印识别结果\n",
    "    except:\n",
    "        print(\"result_str is None\")\n",
    "    #判断识别文本内容，并执行相应的操作\n",
    "    print(f\"第{i}次识别\")\n",
    "    if \"结束录音\" in result_str:\n",
    "        break\n",
    "    i+=1\n",
    "    if i>12:# 12*5=60s,即程序启动后一分钟，无论有没有语音输入，都强制结束运行。\n",
    "        print(\"强制结束录音\")\n",
    "        break\n",
    "if \"通\" in result_str:\n",
    "    os.startfile(\"calc.exe\")\n",
    "  \n",
    "        \n",
    "# #语音合成     \n",
    "# file = tts.Text2Voice(text)\n",
    "# #播放语音文件\n",
    "# r.playwav(file)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "fordetect",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.20"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
